package com.lqs.sofp.servlet;

import com.alibaba.fastjson.JSON;
import com.lqs.sofp.entity.User;
import com.lqs.sofp.service.UserService;
import com.lqs.sofp.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
/**
 * @author lkh
 */
@WebServlet(name = "SelectAllUserServlet", value = "/User/saus")
public class SelectAllUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取所有的用户信息
        UserService uzrService = new UserServiceImpl();
        List<User> userList = uzrService.getAllUser();
        //将数据JSON化
        String jsonString = JSON.toJSONString(userList);
        //响应数据
        response.getWriter().write(jsonString);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
    }
}
